<template>
  <div id="eqMaintainOrderDiv">
    <div class="bodyContent">
      <vxe-table ref="maintainDetailTableRef" class="mytable-scrollbar supplierTableClazz" border="inner" align="center" height="auto" :data="taskEqList" :loading="ploading" :row-config="{ isCurrent: true, isHover: true }" :column-config="{ resizable: true }" resizable show-overflow keep-source>
        <vxe-column type="seq" width="30" title=""></vxe-column>
        <vxe-column field="createTime" title="巡检时间"> </vxe-column>
        <vxe-column field="status" title="巡检内容">
          <template #default="{ row }">
                      <span>
                        <el-tag v-for="(item, index) in row.patrolTaskEqStList" :key="index">{{ item.standardName }}</el-tag>
                      </span>
          </template>
        </vxe-column>
        <vxe-column field="checkResult" title="结果"></vxe-column>
        <vxe-column field="noPass" title="不通过部分"></vxe-column>
        <vxe-column field="noCheck" title="未检部分"></vxe-column>
      </vxe-table>
    </div>
  </div>
</template>
<script setup lang="ts">
// 引入组件区 ==========
import { ref, reactive, getCurrentInstance, onMounted } from 'vue';
import Breadcrumb from '@/components/Breadcrumb.vue';
let { proxy }: any = getCurrentInstance();
import { AppStore } from '@/stores/store';

let store = AppStore();

// 全局变量定义区 ==========
let searchForm = {
  searchValue: '',
  taskStatus:''
};
let tloading = ref(false); //加载状态
let ploading = ref(false); //加载状态

let taskEqList: any = reactive([]);
let maintainStatusList: any = reactive([]); //选择字典
let maintainTypeList: any = reactive([]); //选择字典
let inspectionStatusList: any = reactive([]); //选择字典
let verifylList: any = reactive([]);

let activeName = ref('first');


// 方法定义区 =============
// 页面加载时更新列表(左侧)
onMounted(() => {
  getDictItemsList(); //批量获取字典
});

defineExpose({
  findMaintainDetailList
})

//批量获取字典
async function getDictItemsList() {
  let dictTreeTypeCodes: any = ['maintainType', 'maintainStatus', 'inspectionStatus'];
  const codes = dictTreeTypeCodes.join(',');
  const url = '/api/sys/basDictDetail/findDictDetailListByDictCodes';
  const dictTreeTypeItems: any = await proxy.$http.get(url, { params: { code: codes } });
  const maintainTypes = dictTreeTypeItems.data.find((item) => item.code === 'maintainType');
  maintainTypeList.push(...maintainTypes.detailDataList);
  const maintainStatues = dictTreeTypeItems.data.find((item) => item.code === 'maintainStatus');
  maintainStatusList.push(...maintainStatues.detailDataList);
  const inspectionStatus = dictTreeTypeItems.data.find((item) => item.code === 'inspectionStatus');
  inspectionStatusList.push(...inspectionStatus.detailDataList);
}



function findMaintainDetailList(eqId:any) {

  ploading.value = true;
  taskEqList.length = 0; //放入数据前清空数据
  const url = '/api/eq/patrolTaskEq/findPatrolTaskByEqId';
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: {
        eqId: eqId
      }
    })
    .then((res: any) => {
      if (res.status.code === 1) {
        taskEqList.push(...res.data);
      }
      ploading.value = false;
    })
    .catch((err: any) => {
      ploading.value = false;
      // VxeMessage('获取获取当前字典的规则列表失败',VxeNotifyType.error)
    });
}



async function deleteVerifyMaintain(row: any) {
  const $table = proxy.$refs.verifyTableRef as any;
  if ($table) {
    let cnt = verifylList.findIndex((a: any) => a.id == row.id);
    if (cnt > -1) {
      await $table.remove(row);
      verifylList.splice(cnt, 1);
    }
  }
}
function formatCommon(arr: any, value: any) {
  for (const item of arr) {
    if (item.code == value) {
      return item.name;
    }
  }
}

</script>

<style lang="scss" scoped>
#eqMaintainOrderDiv {
  height: 100%;
  .bodyContent {
    height: calc(100% - 60px);
    .splitpanes {
      background-color: $base-white;
      // 附加按钮间距
      .button-blue,
      .button-red {
        margin: 5px 0 5px 5px;
      }
    }
    .horizontalLine {
      :deep(.splitpanes__splitter) {
        background-color: $base-white;
      }
    }

    // 中间table表格
    .tableBody {
      height: calc(100% - 40px);
    }
    // 质控靶值设定弹框表格
    .tableTargetBody {
      height: 600px;
      .tableTargetBodyRight {
        height: calc(100% - 2px);
        border: 1px solid #e8eaec;

        .closeBtn {
          margin-left: 720px;
        }
      }
    }

    // 右侧保存按钮
    .saveBtn {
      float: right;
      margin: 5px 10px;
    }
    .el-form {
      padding-right: 15px;
      .el-form-item--large {
        margin-bottom: 10px;
      }
      .el-button {
        padding: 5px 2px !important;
      }
      :deep(.el-input__inner) {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }

    // 弹框
    .el-dialog {
      font-weight: 700;
      max-height: 1000px;
      padding: 10px;
    }
    // 最右侧质控项目设定表格
    .tableBox {
      height: calc(100% - 40px);
    }
  }

  :deep(.el-tabs) {
    height: 100%;
    .el-tabs__content {
      height: calc(100% - 70px);
      .el-tab-pane {
        height: 100%;
      }
    }
  }
}
</style>
